import json
import csv
from pathlib import Path

from PIL import Image

# ------------------------------
# 标签管理类
# ------------------------------
class LabelManager:
    def __init__(self, hierarchy_json_path, csv_path):
        # 加载 JSON 层级
        with open(hierarchy_json_path, 'r', encoding='utf-8') as f:
            self.hierarchy = json.load(f)
        # 加载 CSV 映射 LabelName -> DisplayName
        self.label_to_name:dict[str,str] = {}
        with open(csv_path, 'r', encoding='utf-8') as f:
            reader = csv.reader(f)
            for row in reader:
                self.label_to_name[row[0]] = row[1]

    def get_name(self, label_id):
        return self.label_to_name.get(label_id, label_id)

    def get_all_labels(self):
        return list(self.label_to_name.keys())